﻿using Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;


namespace ZoneLine
{
    /// <summary>
    /// PlcsCfgView.xaml 的交互逻辑
    /// </summary>
    public partial class PlcListView : MyViewBase
    {
        private PlcListView()
        {
            InitializeComponent();
            ViewModel = new PlcListViewModel();
            ViewModel.OnShowMsg += ShowMsg;
            ViewModel.OnConfirm += Confirm;
            this.DataContext = ViewModel;
            this.Closed += PlcListView_Closed;

        }

        private void PlcListView_Closed(object sender, EventArgs e)
        {
            _view = null;
        }

        private static PlcListView _view;
        public static PlcListView GetView()
        {
            if (_view == null)
            {
                _view = new PlcListView();
            }

            return _view;
        }

        private void BtnNewPlc_OnClick(object sender, RoutedEventArgs e)
        {
            PlcInfoView view = new PlcInfoView(new t_Plc());
            view.ShowDialog();
            ViewModel.Init();
        }

        private void BtnEdit_OnClick(object sender, RoutedEventArgs e)
        {
            PlcInfoView view = new PlcInfoView((ViewModel as PlcListViewModel).SelectedModel);
            view.ShowDialog();
            ViewModel.Init();
        }
    }
}
